const joi = require('@hapi/joi')
const { updatepwd } = require('../router_handler/userinfo')

//制定id校验规则
const id = joi.number().integer().min(1).required()

//制定nickname校验规则
const nickname = joi.string().required()

//制定email校验规则
const email = joi.string().email().required()

//指定旧密码校验规则
const oldPwd = joi.string().pattern(/^[\S]{6,12}$/).required()

//制定新密码校验规则
const newPwd = joi.not(joi.ref('oldPwd')).concat(oldPwd)

//制定头像校验规则
const avatar = joi.string().dataUri().required()

//更新用户的验证规则
exports.updateUserinfoRuler = {
    body: {
        id,
        nickname,
        email
    }
}

exports.updatepwdRuler = {
    body: {
        oldPwd,
        newPwd
    }
}

exports.updateAvatarRuler = {
    body: {
        avatar
    }
}